#pragma once

#include <freetypegl/vector.h>
#include <freetypegl/vertex-attribute.h>

namespace a2d
{
//------------------------------------------------------------------

	class Vbo2
	{
	public:
		bool Create(const char *format);
		void Render(GLenum mode, int num=-1);
		void Destroy();

		void AddVertices(const void *vertices, const size_t vcount, const GLuint *indices, const size_t icount);

		void Update(const void *vertices, const size_t vcount, const GLuint *indices, const size_t icount);
	private:
		void bufferRenderSetup(GLenum mode);
		void bufferUpload();
		void pushBackVertices(const void *vertices, const size_t vcount);
		void pushBackIndices(const GLuint *indices, const size_t icount);
		void bufferClear();
		
		/** Format of the vertex buffer. */
		char * format;

		/** Vector of vertices. */
		vector_t * vertices;

		/** GL identity of the vertices buffer. */
		GLuint vertices_id;

		/** Vector of indices. */
		vector_t * indices;

		/** GL identity of the indices buffer. */
		GLuint indices_id;

		/** Current size of the vertices buffer in GPU */
		size_t GPU_vsize;

		/** Current size of the indices buffer in GPU*/
		size_t GPU_isize;

		/** GL primitives to render. */
		GLenum mode;

		/** Whether the vertex buffer needs to be uploaded to GPU memory. */
		char state;

		/** Individual items */
		vector_t * items;

		/** Array of attributes. */
		vertex_attribute_t *attributes[MAX_VERTEX_ATTRIBUTE];
	};

//------------------------------------------------------------------
} // namespace a2d
